package JDK8;

import java.util.function.Supplier;

/*
    用lambda表达式和Supplier来求一个数组的最大值
 */
public class SupplierDemo {

    public static void main(String[] args) {
        int maxNum=getMaxNum(()->{
            int arr[]={3,5,2,8};
            int max=arr[0];
            for(int i=0;i<4;i++){
                if(max<arr[i]){
                    max=arr[i];
                }
            }
            return max;
        });
        System.out.println(maxNum);
    }

    public static int getMaxNum(Supplier<Integer> supplier){
        return supplier.get();
    }
}
